// tags Math, Search
// 2004 TCCC Qualification Problem Set 4 - Division I, Level Two
// BEGIN CUT HERE
#include <windows.h>
// END CUT HERE
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <limits>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class BorelSets {
	public:
	int howMany(int size, vector <string> subsets) {
		unsigned int flagUni = (1 << size) - 1;
		set<unsigned int> res;
		for (int i = 0; i < subsets.size(); ++i)
		{
			stringstream ss(subsets[i]);
			int curset = 0;
			int cur;
			while (ss >> cur)
			{
				curset |= 1 << (cur - 1);
			}
			res.insert(curset);
		}

		int lastressize = 0; 
		while (lastressize != res.size())
		{
			lastressize = res.size();
			set<unsigned int> temp = res;
			for (set<unsigned int>::iterator it = temp.begin(); it != temp.end(); ++it)
			{
				unsigned int comp = flagUni - *it; 
				res.insert(comp);
				for (set<unsigned int>::iterator it0 = temp.begin(); it0 != temp.end(); ++it0)
				{
					if (it0 == it) continue;
					res.insert(*it | *it0);
				}
			}
		}
		return res.size();
	}

// BEGIN CUT HERE
	public:
	void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); }
	private:
	template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
	void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
	void test_case_0() { int Arg0 = 4; string Arr1[] = {"1 2",""}; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arg2 = 4; verify_case(0, Arg2, howMany(Arg0, Arg1)); }
	void test_case_1() { int Arg0 = 10; string Arr1[] = {"","1","2","3","4","5","6","7","8","9","10"}; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arg2 = 1024; verify_case(1, Arg2, howMany(Arg0, Arg1)); }
	void test_case_2() { int Arg0 = 5; string Arr1[] = {"","1 1 2","1 1 2 2 1 1","","2 1 1"}; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arg2 = 4; verify_case(2, Arg2, howMany(Arg0, Arg1)); }

// END CUT HERE

};


// BEGIN CUT HERE 
int main()
{
	system("pause");
    BorelSets ___test; 
    ___test.run_test(-1); 
} 
// END CUT HERE 
    
